<?php

require_once("ControlService.php");

function EncodeStr($str)
{
    return iconv('KOI8-R', 'UTF-8', $str);
}

function formChartXML($dataArray, $labelsArray, $legendArray, $title, $parameter, $namex, $namey)
{
    $Title = '';
    $ParamName = $parameter;
    $NameX = $namex;
    $NameY = $namey;

    $XMLChart = new DOMDocument('1.0', 'UTF-8');
    $root = $XMLChart->createElement("chart");
    $root->setAttribute("title", $Title);
    $root->setAttribute("parameter", $ParamName);
    $root->setAttribute("namex", $NameX);
    $root->setAttribute("namey", $NameY);
    $XMLChart->appendChild($root);

    $data = $XMLChart->createElement("data");
    $root->appendChild($data);

    foreach ($dataArray as $keyRow => $rowArray)
    {
        $row = $XMLChart->createElement("row");
        //$row->setAttribute("ID", $keyRow);
        $data->appendChild($row);

        foreach ($rowArray as $keyElement => $valueElement)
        {
            $col = $XMLChart->createElement("col");
            //$col->setAttribute("ID", $keyElement);
            $col->setAttribute("value", $valueElement);
            $row->appendChild($col);
        }
    }

    $labels = $XMLChart->createElement("labels");
    $root->appendChild($labels);
    foreach($labelsArray as $keyLabel => $valueLabel)
    {
        $label = $XMLChart->createElement("label");
        $label->setAttribute("name", $valueLabel);
        $labels->appendChild($label);
    }

    $legend = $XMLChart->createElement("legend");
    $root->appendChild($legend);
    foreach($legendArray as $keyLegend => $valueLegend)
    {
        $item = $XMLChart->createElement("item");
        $item->setAttribute("ID", $keyLegend);
        $item->setAttribute("name", $valueLegend);
        $legend->appendChild($item);
    }

    return $XMLChart;
}



$Title     = "��������� �������" ;
$ParamName = "��������"          ;
$NameX     = "��� 1"             ;
$NameY     = "��� 2"             ;



/*
 // �������� ��������� � ��������� [SideLabelPie]
 $Kind = "SideLabelPie";

 $Data      = array(array(10, 20, 33, 40, 50));
 $Labels    = array(EncodeStr("����� 1"), EncodeStr("����� 2"), EncodeStr("����� 3"), EncodeStr("����� 4"), EncodeStr("����� 5"));
 $Legend    = array();

*/
 


/*

// �������� ��������� � �������� [LegendPie]
$Kind = "LegendPie";

$Data      = array(10, 20, 33, 40, 50);
$Labels    = array(EncodeStr("����� 1"), EncodeStr("����� 2"), EncodeStr("����� 3"), EncodeStr("����� 4"), EncodeStr("����� 5"));
$Legend    = array();

*/



/*
 // ���������� ��������� [CylinderLightBar]
 $Kind = "CylinderLightBar";

 $Data      = array(333, 444, 555, 600, 650, 700, 800);
 $Labels    = array(EncodeStr("�����1"), EncodeStr("�����2"), EncodeStr("�����3"), EncodeStr("�����4"), EncodeStr("�����5"), EncodeStr("�����6"), EncodeStr("�����7"));
 $Legend    = array();


 */


/*
// ���������� ��������� [StackedBar]
$Kind = "StackedBar";

$Data = array (
 0 => array(0 => 10, 1 => 20, 2 => 40),
 1 => array(0 => 20, 1 => 30, 2 => 50),
 2 => array(0 => 30, 1 => 40, 2 => 70)
 );
$Data = array (
0 => array(0 => 10.5),
1 => array(0 => 20),
2 => array(0 => 30)
);
//$Labels    = array(EncodeStr("��������� 1"), EncodeStr("��������� 2"), EncodeStr("��������� 3"));
$Labels    = array(EncodeStr("��������� 1"));
$Legend    = array(
0 => EncodeStr("������ 1"),
1 => EncodeStr("������ 2"),
2 => EncodeStr("������ 3")
);

*/


/*
 // ���������� ���������� ��������� [PercentBar]
 $Kind = "PercentBar";

 $Data = array (
 0 => array(0 => 10, 1 => 20, 2 => 40),
 1 => array(0 => 20, 1 => 30, 2 => 50),
 2 => array(0 => 30, 1 => 40, 2 => 70)
 );
 $Labels    = array(EncodeStr("��������� 1"), EncodeStr("��������� 2"), EncodeStr("��������� 3"));
 $Legend    = array(
 0 => EncodeStr("������ 1"),
 1 => EncodeStr("������ 2"),
 2 => EncodeStr("������ 3")
 );
 */



/*
// ���������� ��������� � ����������� [OverlapBar]
$Kind = "OverlapBar";

$Data = array (
0 => array(0 => 10, 1 => 20, 2 => 30),
1 => array(0 => 30, 1 => 40, 2 => 50),
2 => array(0 => 50, 1 => 60, 2 => 70)
);
$Labels    = array(EncodeStr("��������� 1"), EncodeStr("��������� 2"), EncodeStr("��������� 3"));
$Legend    = array(
0 => EncodeStr("������ 1"),
1 => EncodeStr("������ 2"),
2 => EncodeStr("������ 3")
);
*/



/*
 // ���������� ���������� ��������� [DepthBar]
 $Kind = "DepthBar";

 $Data = array (
 0 => array(0 => 100, 1 => 150, 2 => 200),
 1 => array(0 => 333, 1 => 0, 2 => 220),
 2 => array(0 => 0, 1 => 0, 2 => 0)
 );
 $Labels    = array(EncodeStr("��������� 1"), EncodeStr("��������� 2"), EncodeStr("��������� 3"));
 $Legend    = array(
 0 => EncodeStr("������ 1"),
 1 => EncodeStr("������ 2"),
 2 => EncodeStr("������ 3")
 );
 */




// ��������� ������ [Pareto]
$Kind = "Pareto";

$Data      = array(40, 60, 50);
$Labels    = array(EncodeStr("�����1"), EncodeStr("�����2"), EncodeStr("�����3"));
$Legend    = array();



/*
 // ������������� ��������� [Multiline]
 $Kind = "Multiline";

 $Data = array (
 0 => array(0 => 10, 1 => 20, 2 => 30),
 1 => array(0 => 20, 1 => 30, 2 => 40),
 2 => array(0 => 12, 1 => 13, 2 => 15)
 );
 $Labels    = array(EncodeStr("��������� 1"), EncodeStr("��������� 2"), EncodeStr("��������� 3"));
 $Legend    = array(
 0 => EncodeStr("������ 1"),
 1 => EncodeStr("������ 2"),
 2 => EncodeStr("������ 3")
 );
 */



/*
 // ������������� ��������� [MultiRadar]
 $Kind = "MultiRadar";

 $Data = array (
 0 => array(0 => 10, 1 => 20, 2 => 30),
 1 => array(0 => 30, 1 => 40, 2 => 50),
 2 => array(0 => 50, 1 => 60, 2 => 70)
 );
 $Labels    = array(EncodeStr("��������� 1"), EncodeStr("��������� 2"), EncodeStr("��������� 3"));
 $Legend    = array(
 0 => EncodeStr("������ 1"),
 1 => EncodeStr("������ 2"),
 2 => EncodeStr("������ 3")
 );
 */



// ��������� � ���������� ������ ����� ������� ������� �������
$Data      = $Data                 ;
$Labels    = $Labels               ;
$Legend    = $Legend               ;

$Title     = EncodeStr($Title)     ;
$ParamName = EncodeStr($ParamName) ;
$NameX     = EncodeStr($NameX)     ;
$NameY     = EncodeStr($NameY)     ;

$xml = formChartXML($Data, $Labels, $Legend, $Title, $ParamName, $NameX, $NameY);

include 'XMLChart.php';
include 'lib/Settings.php';
$XMLChart = new XMLChart($xml->saveXML());

// ��������� � �������
$service   = new ControlService("http://127.0.0.1/ChartService/TransferChart.wsdl");
$result    = $service->plotChart($xml->saveXML(), $Kind) ;

echo $result;

if ($result["error"] == 0)
{
    echo "<img src='" . $result["result"] . "'/>";
}
else
{
    echo $result["result"];
}

//echo "<img src='" . $service->plotChart($Data, $Labels, $Legend, $Kind, $Title, $ParamName, $NameX, $NameY) . "'/>";
?>
